home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / raytrace / real3d / rl_dvlpr.lha / Source / hrcode.c < prev    next >
C/C++ Source or Header  |  1992-07-22  |  6KB  |  195 lines

  1.  
  2. /******************************************************************\
  3.  This file contains the library functions for ACS Harlequin. 
  4.  In this example alpha channel properties of Harlequin are used, but
  5.  no multiple screens are supported. Therefore, the handle argument
  6.  and the internal 'hscreen' pointer have the same value, and hence
  7.  most functions ignore the 'hnd' argument and use 'hscreen' instead.
  8.  I hope this is not confusing.
  9.    
  10.  Custom saving is not implemented.
  11.  
  12.  It is quite easy to modify the functions to fit the properties of 
  13.  another similar device. To recompile the modified file, use the command
  14.  
  15.     'lc -y -v -O hrcode' (SAS C)
  16.     
  17. \*******************************************************************/
  18.  
  19.  
  20. #include <exec/types.h>
  21. #include <intuition/intuition.h>
  22. #include <intuition/intuitionbase.h>
  23. #include <libraries/harlequin.h>
  24. #include "dspdrvbase.h"
  25. #include <proto/all.h>
  26. #include <proto/harlequin.h>
  27.  
  28. struct ExecBase *SysBase;
  29. struct R3DDspDrvBase *R3DDspDrvBase;
  30. struct IntuitionBase *IntuitionBase;
  31.  
  32.  
  33. /* Harlequin related data items: */
  34.  
  35. struct Library *HarlequinBase;
  36.  
  37. struct HNewScreen myscreen = 
  38.     {0,0,740,576,HINTERLACE|HPAL|HBORDERLESS|HNEAREST,-1,0,0};
  39. struct HImageBlock hbl = {0,1,IB_RED|IB_GREEN|IB_BLUE|IB_ALPHA,};
  40.  
  41. struct HScreen *hscreen;
  42.  
  43.  
  44. /* Library functions: */
  45.  
  46. R3DInitDspDrv()
  47. {   if(hscreen) return(NULL); /* Exclusive access through this library !!*/
  48.     SysBase = R3DDspDrvBase->SysLib;
  49.     if(!(HarlequinBase = OpenLibrary("harlequin.library",0L))) return(FALSE);
  50.     
  51.     if(hscreen = HOpenScreen(&myscreen))
  52.         HScreenFunction(hscreen,SCREEN_ON|SCREEN_FRONT);
  53.     else goto error;
  54.  
  55.     return(hscreen);
  56. error:
  57.     CloseLibrary(HarlequinBase); HarlequinBase = NULL;
  58.     return(FALSE);
  59. }
  60.  
  61. void
  62. R3DFreeDspDrv(int hnd) 
  63. {   if(hscreen) HCloseScreen(hscreen); 
  64.     hscreen = NULL;
  65.     if(HarlequinBase) CloseLibrary(HarlequinBase);
  66.     HarlequinBase = NULL;
  67. }
  68.  
  69. void
  70. R3DWriteLine(hnd,buf,pixnum,x,y) /* writes rgba of pixnum pixels */
  71. int hnd;
  72. int *buf;
  73. int pixnum,x,y;
  74. {   if(!hscreen) return;
  75.     hbl.Data = buf; hbl.Width = pixnum;
  76.     HClipBlockScreen(&hbl,0,0,hscreen,x,y,pixnum,1);        
  77. }
  78.  
  79. void 
  80. R3DReadLine(hnd,buf,pixnum,x,y) /* returns rgba of pixnum pixels */
  81. int hnd, *buf;
  82. int pixnum,x,y; /*The length and the position of the line to be read */
  83. {   
  84.     if(!hscreen) return;
  85.     hbl.Data = buf; hbl.Width = pixnum;
  86.     HClipScreenBlock(hscreen,x,y,&hbl,0,0,pixnum,1);
  87. }
  88.  
  89. void 
  90. R3DClsScr(int hnd, int color)
  91. {   if(!hscreen) return;
  92.     hscreen->FgPen = color; HClearScreen(hscreen);   
  93. }
  94.  
  95. void
  96. R3DGetSize(int hnd, int *x, int *y)
  97. {   *x = hscreen->Width; *y = hscreen->Height;
  98. }
  99.         
  100. void 
  101. R3DSetMode(int hnd)
  102. {   struct IntuiMessage *message;
  103.     struct Window *aw;
  104.     ULONG class,gadgetid;
  105.     APTR iaddress;
  106.  
  107.     static WORD gsquare[6] = {0,10, 0, 0,79,0}; 
  108.     static WORD gsquare2[6] = {0,10,79,10,79,0}; 
  109.  
  110.     static struct Border gborder2 = {0,0,2,3,JAM2,3,(WORD *)&gsquare2,NULL,};
  111.     static struct Border gborder = {0,0,1,3,JAM2,3,(WORD *)&gsquare,&gborder2,};
  112.     
  113.     static struct IntuiText _headertext = 
  114.         {1,1,JAM1,9, 4,NULL,"Select frame buffer modes",NULL,};
  115.     static struct IntuiText headertext =
  116.         {2,2,JAM1,11,5,NULL,"Select frame buffer modes",&_headertext,};
  117.  
  118.     static struct IntuiText lace_text = {1,5,JAM1,4,2,NULL,"INTERLACE",NULL,};
  119.     static struct IntuiText hires_text = {1,5,JAM1,20,2,NULL,"HIRES",NULL,};
  120.     static struct IntuiText otext = { 1,1,JAM1,30,2,NULL,"OK",0,};
  121.     static struct IntuiText ctext = {1,1,JAM1,14,2,NULL,"CANCEL",NULL,};  
  122.  
  123.     static struct Gadget lace_gadget =
  124.     {    NULL,130,25,80,11,GADGHCOMP,TOGGLESELECT,BOOLGADGET|REQGADGET,
  125.         (APTR)&gborder,NULL,&lace_text,NULL,NULL,0,NULL,
  126.     };
  127.  
  128.     static struct Gadget hires_gadget =
  129.     {    &lace_gadget,10,25,80,11,GADGHCOMP,TOGGLESELECT,BOOLGADGET|REQGADGET,
  130.         (APTR)&gborder,NULL,&hires_text,NULL,NULL,0,NULL,
  131.     };
  132.     
  133.     static struct Gadget cancel_gadget =
  134.     {    &hires_gadget,130,45,80,11,GADGHCOMP,ENDGADGET | RELVERIFY,
  135.     BOOLGADGET|REQGADGET,(APTR)&gborder,NULL,&ctext,NULL,NULL,2,NULL,
  136.     };
  137.  
  138.     static struct Gadget ok_gadget=
  139.     {    &cancel_gadget,10,45,80,11,GADGHCOMP,ENDGADGET | RELVERIFY,
  140.         BOOLGADGET|REQGADGET,(APTR)&gborder,NULL,&otext,NULL,NULL,1,NULL,
  141.     };
  142.  
  143.     static WORD req_square[6] = {0,59,0,0,219,0};
  144.     static WORD req_square2[6] = {0,59,219,59,219,0};
  145.  
  146.     static struct Border req_border2 =
  147.         { 0,0,2,2,JAM1,3,(WORD *)&req_square2,NULL,};
  148.     static struct Border req_border =
  149.         { 0,0,1,1,JAM1,3,(WORD *)&req_square,&req_border2,};
  150.  
  151.     static struct Requester mode_req =
  152.     {      NULL,100,50,220,60,0,0,&ok_gadget,&req_border,&headertext,
  153.     NULL,0,NULL,{NULL},{NULL},NULL,{NULL},
  154.     };
  155.     
  156.     if(!hscreen) return;
  157.     
  158.     if(!(IntuitionBase=(struct IntuitionBase *)
  159.         OpenLibrary("intuition.library",0))) return;
  160.  
  161.     if(hscreen->Type & HINTERLACE) lace_gadget.Flags |= SELECTED;
  162.     else lace_gadget.Flags &= ~SELECTED;
  163.     if(hscreen->Width  == 910) hires_gadget.Flags |= SELECTED; 
  164.     else hires_gadget.Flags &= ~SELECTED;
  165.  
  166.     aw = IntuitionBase->ActiveWindow;
  167.     if(!Request(&mode_req,aw)) goto cleanexit;
  168.     
  169.     for(;;)
  170.     {   while(!(message=(struct IntuiMessage *)GetMsg(aw->UserPort)))
  171.             Wait(1<<aw->UserPort->mp_SigBit);
  172.         if(message)
  173.         {   class = message->Class;
  174.             iaddress = message->IAddress;
  175.             ReplyMsg(message);
  176.             if(class == GADGETUP) break;
  177.         }        
  178.     }
  179.     gadgetid=((struct Gadget *)iaddress)->GadgetID;
  180.     if(gadgetid == 1)
  181.     {   if(lace_gadget.Flags & SELECTED) myscreen.Type |= HINTERLACE;
  182.     else myscreen.Type &=~HINTERLACE;
  183.     if(hires_gadget.Flags & SELECTED) myscreen.Width = 910;
  184.     else myscreen.Width = 740;
  185.         HConvertScreen(hscreen,&myscreen,0);
  186.     }
  187.   cleanexit:  CloseLibrary(IntuitionBase);
  188. }
  189.  
  190. void
  191. R3DCustomSave(int hnd, char *name, int x, int y, int w, int h)
  192. {   
  193. }
  194.  
  195.